//
// Delaunay Triangulation
//
// Homework of CG lesson (Fall 2009) in Tsinghua University.
// All rights reserved.
//

// temp include, delete later if necessary
#include "stdafx.h"

#include "line2d.h"

// User headers
#include "base.h"

Line2d::Line2d(void)
    :a(1.0), b(1.0), c(1.0)
{
}

Line2d::Line2d(const Point2d& p1, const Point2d& p2)
{
    a = p2.y - p1.y;
    b = p1.x - p2.x;
    c = p1.y * (p2.x - p1.x) - p1.x * (p2.y - p1.y);
}

double Line2d::eval(const Point2d& p) const
{
    return (a * p.x + b * p.y + c);
}

int Line2d::classify(const Point2d& p) const
{
    double d = eval(p);

    if (d < -TOLERANCE)
        return -1;
    else if (d > TOLERANCE)
        return 1;
    else
        return 0;
}
